# import logging
# import time
#
# import pymysql
#
# from celery_tasks.main import app
# from vne_erp.vne_erp.apps.orders.views import ScriptForXiaomi
#
# logger = logging.getLogger('django')
#
# @app.task(name='script_xiaomi')
# def script_xiaomi():
#
#     i = 1
#     while True:  # 定时任务
#
#         # 和数据库建立连接
#         conn = pymysql.connect('localhost', 'vne123', '123', charset='utf8')
#
#         # 创建游标
#         cur = conn.cursor()
#
#         # 选择数据库
#
#         cur.execute('use vnemy')
#
#         # 导入数据
#         # 1 创建对象
#
#         sfx = ScriptForXiaomi()
#
#         # 2 爬取数据
#         response = sfx.get_response_data()
#
#         # 3 数据转换与提取
#         data_of_tuple = sfx.counter_data(response)
#
#         # 4 将数据存入mysql
#         sfx.data_to_mysql(cur, data_of_tuple)
#
#         cur.close()
#         conn.commit()
#         # 关闭数据库服务器连接，释放内存
#         conn.close()
#
#         time.sleep(3)
#         i += 1
#         print("更新第%s次" % i)